// Elements used in implementation of doubly linked lists.
// (c) 1998, 2001 duane a. bailey
package Calculadora;

/**
 * A class supporting a doubly linked list element.  Each element
 * contains a value and maintains references to the previous and next 
 * nodes in the list.
 * <P> 
 * 
 * 
 * @version $Id: DoublyLinkedListElement.java,v 4.0 2000/12/27 20:57:33 bailey Exp bailey $
 * @author, 2001 duane a. bailey
 * @see structure.DoublyLinkedList
 */
public class DoublyLinkedListElement<E>
{
    /**
     * The actual value stored within element; provided by user.
     */
    protected E data;
    /**
     * The reference of element following.
     */
    protected DoublyLinkedListElement nextElement;
    /**
     * The reference to element preceding.
     */
    protected DoublyLinkedListElement previousElement;

    /**
     * Construct a doubly linked list element.
     *
     * @param v The value associated with the element.
     * @param next The reference to the next element.
     * @param previous The reference to the previous element.
     */
    public DoublyLinkedListElement(E v,
			    DoublyLinkedListElement next,
			    DoublyLinkedListElement previous)
    {
	data = v;
	nextElement = next;
	if (nextElement != null) {
            nextElement.previousElement = this;
        }
	previousElement = previous;
	if (previousElement != null) {
            previousElement.nextElement = this;
        }
    }
 /**
     * Access the reference to the next value.
     *
     * @post returns the element that follows this
     *
     * @return Reference to the next element of the list.
     */
    public DoublyLinkedListElement next()
    {
	return nextElement;
    }
    /**
     * Get value stored within the element.
     *
     * @post returns value stored here
     * 
     * @return The reference to the value stored.
     */
    public E value()
    {
	return data;
    }

    /**
     * Set reference to the next element.
     *
     * @post sets value associated with this element
     * 
     * @param next The reference to the new next element.
     */
    public void setNext(DoublyLinkedListElement next)
    {
	nextElement = next;
    }

    /**
     * Set the reference to the previous element.
     *
     * @post establishes a new reference to a previous value
     * 
     * @param previous The new previous element.
     */
    public void setPrevious(DoublyLinkedListElement previous)
    {
	previousElement = previous;
    }

}	

